extends CharacterBody2D

func _physics_process(_delta):
	player_move()

#移动速度
var speed = 260
#移动方向
var input = Vector2()

func player_move():
	input.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
	input.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
	if input != Vector2.ZERO :
		if velocity.x < 0:
			$AnimatedSprite2D.play("left")
			$AnimatedSprite2D.flip_h = false
		elif velocity.x > 0:
			$AnimatedSprite2D.play("left")
			$AnimatedSprite2D.flip_h = true
		if velocity.y < 0 and  velocity.x == 0:
			$AnimatedSprite2D.play("up")
		elif velocity.y > 0 and  velocity.x == 0:
			$AnimatedSprite2D.play("down")
		velocity = input.normalized() * speed
	else :
		velocity = Vector2.ZERO
	move_and_slide()
